package elEMAS.impl;

import java.util.ArrayList;
import java.util.List;

import elEMAS.inf.*;

public class EmasIsland<Genotype> implements Island<Genotype> {
	
    private int _energy;
	private List<Agent<Genotype>> _agents;
	
	/**
	 * It is changed during step
	 */
	private List<Agent<Genotype>> _agentsOp;

	public EmasIsland(int aInitialEnergy) {
	    
		this._agents = new ArrayList<Agent<Genotype>>();
		this._agentsOp = new ArrayList<Agent<Genotype>>();
		this._energy = aInitialEnergy;
		//System.out.println("Jestem nowa wyspa! Dostalam poczatkowa energie " + aInitialEnergy + ".");
	}

	public void addAgent(Agent<Genotype> aAgent) {
		this._agentsOp.add(aAgent);
	}
	
	public List<Agent<Genotype>> getAgents() {
		return this._agents;
	}
	
	public List<Agent<Genotype>> getAgentsOp() {
		return this._agentsOp;
	}

	public void removeAgent(Agent<Genotype> aAgent) {
		this._agentsOp.remove(aAgent);
	}

	public void increaseEnergy(int aAmount) {
		this._energy += aAmount;
	}

	/**
	 * Copy _agentsOp to _agents
	 */
	public void copyList() {
		this._agents.clear();
		this._agents.addAll(_agentsOp);
	}

	//zwraca energie wyspy do srodowiska i zeruje jej energie
	public int receiveEnergy() {
		//System.out.println("receiveEnergy Wyspa: energia " + this._energy);
		int tmpEnergy = this._energy;
		this._energy = 0;
		
		return tmpEnergy;
	}
	
	public int getEnergy() {
		return this._energy;
	}	
}